import axios from 'axios'

import { ICusEmailTemplateInfo, IEmailTemplateInfo, ISendReq } from '../interface'
import './__mock__'

/** 获取模板信息 */
export const apiGetEmialTemplateInfo = async ({
  noticeId,
}: {
  /** 客户通知ID */
  noticeId: number
}): Promise<IEmailTemplateInfo> => {
  return axios.post(`/tmsapi/customer_notice/getTemplateInfo`, { noticeId }).then(res => {
    const data = res.$data as IEmailTemplateInfo
    return {
      ...data,
      dynamicFields: data.dynamicFields || [],
    }
  })
}

/** 获取自定义模板信息 */
export const apiGetCusEmialTemplateInfo = async (): Promise<ICusEmailTemplateInfo> => {
  return axios.post(`/tmsapi/customer_notice/getCustomTemplateInfo`).then(res => {
    const data = res.$data as ICusEmailTemplateInfo
    return {
      ...data,
    }
  })
}

/** 发送模板邮件 */
export const apiSendEmailTemplate = async (req: ISendReq) => {
  await axios.post(`/tmsapi/template/sendEmailByTemplate`, req)
}

/** 标记路由邮件已发送 */
export const apiFinishNotice = async (noticeId: number) => {
  await axios.post(`/tmsapi/customer_notice/finishNotice`, { noticeId })
}
